

export function setSession(name,data) {
    let res=JSON.stringify(data)
    sessionStorage.setItem(name,res)
}
export function getSession(name) {
    let res= JSON.parse(sessionStorage.getItem(name))
    return res
}
export function setLocalSession(name,data) {
    let res=JSON.stringify(data)
    localStorage.setItem(name,res)
}
export function getLocalSession(name) {
    let res= JSON.parse(localStorage.getItem(name))
    return res
}

export function throttle(fn, wait = 800) {
    let that=this
    let previous = 0//记录时间
    return function proxy() {
        let now = +new Date()
        if (now - previous > wait) {
            fn.apply(that,arguments)
            previous=now
        }

    }
}
export function debounce(handle,wait=300,search){
    console.log(search);
      // 参数判断
      let timer  = null
     console.log(handle);
      return function proxy(){ 
        //this 指向btn
        console.log('proxy',this)
        let that = this
        let arg = arguments //arguments不定参 当传递的参数不确定时 可以使用这个
        clearTimeout(timer)
        timer =  setTimeout(()=>{
          handle.call(that,arg[0])
          //hanlde没有执行
        },wait)
  
      }
    }

